﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Schism.Mapping
{
    public enum CellConverterEnum {
        Open = 1,
        Closed = 2,
        Stone = 3,
        Gold = 4,
        Water = 5,
    }
    public static class CellMapBuilder
    {
        public static CellMap Basic
        {
            get
            {
                int[,] map = new int[,]
                {
                    {3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 },
                    {3, 2, 2, 2, 2, 2, 2, 2, 2, 5, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3 },
                    {3, 2, 2, 1, 2, 2, 2, 2, 2, 5, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3 },
                    {3, 2, 2, 1, 2, 2, 2, 2, 2, 5, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3 },
                    {3, 2, 2, 1, 2, 2, 2, 2, 2, 5, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3 },
                    {3, 2, 2, 1, 2, 2, 2, 2, 2, 5, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3 },
                    {3, 2, 2, 1, 2, 2, 2, 2, 2, 5, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3 },
                    {3, 2, 2, 1, 2, 2, 2, 2, 2, 5, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3 },
                    {3, 2, 2, 1, 2, 2, 2, 2, 2, 5, 2, 2, 2, 4, 4, 2, 2, 2, 2, 3 },
                    {3, 2, 2, 1, 2, 2, 2, 2, 2, 5, 2, 2, 2, 2, 4, 2, 2, 2, 2, 3 },
                    {3, 2, 2, 2, 2, 2, 2, 2, 2, 5, 2, 2, 2, 4, 4, 2, 2, 2, 2, 3 },
                    {3, 2, 2, 2, 2, 2, 2, 2, 2, 5, 2, 2, 2, 4, 2, 2, 2, 2, 2, 3 },
                    {3, 2, 2, 2, 2, 2, 2, 2, 2, 5, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3 },
                    {3, 2, 2, 2, 2, 2, 2, 2, 2, 5, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3 },
                    {3, 2, 2, 2, 2, 2, 2, 1, 1, 5, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3 },
                    {3, 2, 2, 2, 2, 2, 2, 2, 1, 5, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3 },
                    {3, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3 },
                    {3, 4, 4, 2, 2, 2, 2, 2, 2, 5, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3 },
                    {3, 4, 4, 4, 4, 2, 2, 2, 2, 5, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3 },
                    {3, 4, 4, 4, 4, 2, 2, 2, 2, 5, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3 },
                    {3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 },
                };

                CellBase[,] baseMap = new CellBase[map.GetLength(0), map.GetLength(1)];

                for (int y = 0; y < baseMap.GetLength(0); y++)
                {
                    for (int x = 0; x < baseMap.GetLength(1); x++)
                    {
                        switch ((CellConverterEnum)map[y,x])
                        {
                            case CellConverterEnum.Open:
                                 baseMap[y, x] = CellFactory.Create<Cell>(new Core.DungeonPos(x, y),
                                     new KeyValuePair<string, object>[] {
                                        new KeyValuePair<string,object>("State", CellState.Open),
                                    });
                                break;
                            case CellConverterEnum.Closed:
                                baseMap[y, x] = CellFactory.Create<Cell>(new Core.DungeonPos(x, y));
                                break;

                            case CellConverterEnum.Stone:
                                baseMap[y, x] = CellFactory.Create<StoneCell>(new Core.DungeonPos(x, y));
                                break;

                            case CellConverterEnum.Water:
                                baseMap[y, x] = CellFactory.Create<LiquidCell>(new Core.DungeonPos(x, y)); 
                                break;

                            case CellConverterEnum.Gold:
                                baseMap[y, x] = CellFactory.Create<GoldSeamCell>(new Core.DungeonPos(x, y), 
                                new KeyValuePair<string,object>[] {
                                        new KeyValuePair<string,object>("GoldRepository", 100),
                                    });
                                break;
                        } 
                    }
                }

                return new CellMap(baseMap);
            }

        }
    }
}
